package org.jasig.cas.cuscon;

import org.jasig.cas.util.UniqueTicketIdGenerator;
import org.jasig.cas.web.support.WebUtils;
import org.springframework.webflow.action.AbstractAction;
import org.springframework.webflow.execution.Event;
import org.springframework.webflow.execution.RequestContext;

import javax.servlet.http.HttpServletRequest;

/**
 * Created by Administrator on 2017/5/25/025.
 */
public class ProvideLoginTicketAction extends AbstractAction {

    private static final String PREFIX = "LT";

    @Override
    protected Event doExecute(RequestContext requestContext) throws Exception {
        final HttpServletRequest request = WebUtils.getHttpServletRequest(requestContext);
        if (request.getParameter("get-lt") != null && request.getParameter("get-lt").equalsIgnoreCase("true")) {
            final String loginTicket = this.ticketIdGenerator.getNewTicketId(PREFIX);
            WebUtils.putLoginTicket(requestContext, loginTicket);
            return result("loginTicketRequested");
        }
        return result("continue");
    }

    private UniqueTicketIdGenerator ticketIdGenerator;

    public void setTicketIdGenerator(final UniqueTicketIdGenerator generator) {
        this.ticketIdGenerator = generator;
    }
}
